package com.wutao.panzh.index.content.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.panzh.UtilEntity.ResultVO;
import com.panzh.entity.SceneryClassification;
import com.panzh.entity.SceneryItem;
import com.panzh.entity.index.IndexSceneryItem;
import com.panzh.myconst.CommonConst;
import com.wutao.panzh.service.SceneryClassificationService;
import com.wutao.panzh.service.SceneryItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class IndexSceneryHandler {

    @Reference
    private SceneryClassificationService sceneryClassificationService;

    @Reference
    private SceneryItemService sceneryItemService;

    @ResponseBody
    @RequestMapping("/get/scenery/classification")
    public ResultVO getSceneryClassification(){
        List<SceneryClassification> allClassIfication = null;
        try {
            allClassIfication = sceneryClassificationService.getAllClassIfication();
        } catch (Exception e) {
            return new ResultVO<String>(ResultVO.FAILED, CommonConst.GET_INFORMATION_FAILED,ResultVO.NO_DATA );
        }
        return new ResultVO<List<SceneryClassification>>(ResultVO.SUCCESS, ResultVO.NO_MSG,allClassIfication);
    }

    /**
     * 咱们默认还是要使用一个分页的东东的。classificationId是分类的id，更加方便我们进行属性的筛选；
     * @return
     */
    @ResponseBody
    @RequestMapping("/get/all/index/sceneryItem")
    public ResultVO getAllIndexSceneryItem(@RequestParam(value="pageNo",defaultValue="1") Integer pageNo,
                                           @RequestParam("classificationId") Integer classificationId){
        PageInfo<IndexSceneryItem> indexSceneryItemPageInfo = sceneryItemService.getAllIndexSceneryItem(pageNo,classificationId);
        return new ResultVO<PageInfo<IndexSceneryItem>>(ResultVO.SUCCESS,ResultVO.NO_MSG ,indexSceneryItemPageInfo);
    }

//    href='show_scenery_details?itemId=" + itemId + "'
    @RequestMapping("show_scenery_details")
    public String getShowIndexSceneryDetails(@RequestParam("itemId") Integer itemId, Model model){
        //转来转去，我是真的吧自己弄烦了。
        SceneryItem sceneryItem = sceneryItemService.getSceneryItemById(String.valueOf(itemId));
        model.addAttribute("sceneryItem",sceneryItem);
        return "SceneryDetails";

    }
}
